package com.medical.Controller.admin;

import com.medical.DTO.AppointmentsDTO;
import com.medical.DTO.AppointmentsPageDTO;
import com.medical.Service.AppointmentsService;
import com.medical.result.PageResult;
import com.medical.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/admin")
@CrossOrigin("*")
@Tag(name = "预约管理类")
@Slf4j
public class AppointmentsController {
    @Autowired
    private AppointmentsService appointmentsService;

    /*

    * 添加预约
    * @param appointmentsDTO
    * @return
     */
    @PostMapping("/addAppointments")
    @Operation(summary = "添加预约")
    public Result addAppointments(@RequestBody AppointmentsDTO appointments) {
        log.info("添加预约：{}", appointments);
        appointmentsService.addAppointments(appointments);
        return Result.success();
    }

    /*
    * 更新预约
    * @param appointmentsDTO
    * @return
     */
    @PutMapping("/updateAppointments")
    @Operation(summary = "更新预约")
    public Result updateAppointments(@RequestBody AppointmentsDTO appointments) {
        log.info("更新预约：{}", appointments);
        appointmentsService.updateAppointments(appointments);
        return Result.success();
    }

    /*
    * 删除预约
    * @param id
    * @return
     */
    @DeleteMapping("/deleteAppointments")
    @Operation(summary = "删除预约")
    public Result deleteAppointments(@RequestParam Integer id) {
        log.info("删除预约，id：{}", id);
        appointmentsService.deleteAppointments(id);
        return Result.success();
    }

    /*
    * 根据id查询预约
    * @param id
    * @return
     */
    @GetMapping("/getAppointmentsById")
    @Operation(summary = "根据id查询预约")
    public Result getAppointmentsById(@RequestParam Integer id) {
        log.info("根据id查询预约，id：{}", id);
        AppointmentsDTO appointments = appointmentsService.getById(id);
        return Result.success(appointments);
    }

    /*
    * 分页查询预约列表
    * @param page
    * @param pageSize
    * @param userId
    * @param doctorId
    * @param beginTime
    * @param endTime
    * @param status
    * @return
     */
    @GetMapping("/pageQueryAppointments")
    @Operation(summary = "分页查询预约列表")
    public Result pageQuery(AppointmentsPageDTO appointments) {
        log.info("分页查询预约列表，参数：pageQueryAppointments{}", appointments);
        PageResult pageResult = appointmentsService.pageQuery(appointments);
        return Result.success(pageResult);
    }

    /*
    * 更新预约状态
    * @param id
    * @param status
    * @return
     */
    @PutMapping("/updateAppointmentsStatus")
    @Operation(summary = "更新预约状态")
    public Result updateStatus(@RequestParam Integer id, @RequestParam String status) {
        log.info("更新预约状态，id：{}，status：{}", id, status);
        appointmentsService.updateStatus(id, status);
        return Result.success();
    }
}
